
MAKEFLAGS = -s @MAKEJOBS@

SHELL = @SHELL@
top_srcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@

@SET_MAKE@
DISTRIB = @PACKAGE_TARNAME@-@PACKAGE_VERSION@
CCDEPMODE = @CCDEPMODE@

# defaults
CXX = @CCACHE@ @DISTCC@ @CXX@ -static
LD = @CXX@ -static
CXXDEBUG = @CCACHE@ @DISTCC@ @CXXDEBUG@
LDDEBUG = @CXXDEBUG@
LIBS = @LIBS@ @ZLIB@

# utils
STRIP = @STRIP@
DIFF = @DIFF@
SED = @SED@
GREP = @GREP@
AWK = @AWK@
YACC = @YACC@
VALGRIND = @VALGRIND@

DEBCXXFLAGS = -DDEBUG -fno-inline -g3 -ggdb3 -Wshadow -O0 @DEBGCC3@ @GCC4DEB@
CFLGS = @GCC3@

MAKE_BDLIB = $(MAKE) 'MAKE=$(MAKE)' 'CXX=$(CXX)' 'LD=$(LD)' 'CCDEPMODE=$(CCDEPMODE)' \
'STRIP=$(STRIP)' 'CFLGS=$(CFLGS) @NOUNITSGCC3@' 'LIBS=$(LIBS)' 'BINBUILD=(distrib)'

MAKE_DEBUG = $(MAKE) 'MAKE=$(MAKE)' 'CXX=$(CXXDEBUG)' 'LD=$(LDDEBUG) -g' 'CCDEPMODE=$(CCDEPMODE)'  \
'STRIP=touch' 'CFLGS=$(CFLGS) $(DEBCXXFLAGS) @DEBNOUNITSGCC3@' 'LIBS=$(LIBS)' 'BINBUILD=(debug)'

MAKE_UNITS = $(MAKE) 'MAKE=$(MAKE)' 'CXX=$(CXXDEBUG)' 'LD=$(LDDEBUG) -g' 'CCDEPMODE=$(CCDEPMODE)' \
'STRIP=touch' 'CFLGS=$(CFLGS) $(DEBCXXFLAGS)' 'LIBS=$(LIBS)'

MAKE_UTILS = $(MAKE) 'MAKE=$(MAKE)' 'CXX=$(CXXDEBUG)' 'STRIP=touch' 'CCDEPMODE=$(CCDEPMODE)' \
'CFLGS=$(CFLGS) $(DEBCXXFLAGS)' 'LIBS=$(LIBS)' 'LD=$(LDDEBUG) -g'

.PHONY: default clean distclean bdlib debug general check check.quiet checkclean.bdlib checkclean.debug buildcheck
.NOTPARALELL: checkclean.bdlib checkclean.debug

default: bdlib

clean:
	-+@cd src && $(MAKE) clean
	-+@cd build && $(MAKE) clean
	@rm -f build/stamp.* *~ src/*~ configure.temp utctime@EXEEXT@ ts@EXEEXT@

distclean: clean
	-+@cd build && $(MAKE) distclean
	-+@cd src && $(MAKE) distclean
	@rm -f Makefile config.log config.status configure.lineno
	@rm -rf *-$(VERSION)/ autom4te.cache/ autoscan.log configure.scan

checkclean.bdlib:
	@(if test -f build/stamp.debug; then \
	echo "[*] Cleaning up alternate build"; \
	$(MAKE) MAKEFLAGS=-s clean; \
	fi)
	@touch build/stamp.bdlib

checkclean.debug:
	@(if test -f build/stamp.bdlib; then \
	echo "[*] Cleaning up alternate build"; \
	$(MAKE) MAKEFLAGS=-s clean; \
	fi)
	@touch build/stamp.debug

bdlib: checkclean.bdlib general
	@echo "[*] Making BDLIB"
	+@cd src && $(MAKE_BDLIB) bdlib


debug: checkclean.debug general
	@echo "[*] Making BDLIB (debug)"
	+@cd src && $(MAKE_DEBUG) bdlib

general:

buildcheck: checkclean.debug
	+@cd src && $(MAKE_DEBUG) bdlib
	+@cd src/tests && $(MAKE_UNITS) units
	+@cd build && ${MAKE_DEBUG} check


check: checkclean.debug general buildcheck
	@echo "[*] Running unit tests..."
	@$(VALGRIND) build/UnitRunner@EXEEXT@

check.quiet: checkclean.debug general buildcheck
	@echo "[*] Running unit tests..."
	@$(VALGRIND) build/UnitRunner@EXEEXT@ quiet

checkquick: checkclean.debug general buildcheck
	@echo "[*] Running unit tests..."
	build/UnitRunner@EXEEXT@ quiet
